package com.ruomeng.robot.util;


import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import com.alibaba.fastjson.JSONObject;




public class SmsTool {

	
	
	/**
	 * 短信发送方法
	 * 
	 */
    public static String noteSend(String name,String phone)
    {
    	
    	name="\""+name+"\"";
    	String host = "http://ali-sms.showapi.com";
	    String path = "/sendSms";
	    String method = "GET";
	    String appcode = "a17ffbb248b04679a6d119edcae99ce3";
	    Map<String, String> headers = new HashMap<String, String>();
	    headers.put("Authorization", "APPCODE " + appcode);
	    Map<String, String> querys = new HashMap<String, String>();
	    String str="{\"name\":"+name+"}";
	    querys.put("content", str);
	    querys.put("mobile", phone);
	    querys.put("tNum", "T170317001218");//短信预警模块


	    try {
	    	/**
	    	* 重要提示如下:
	    	* HttpUtils请从
	    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
	    	* 下载
	    	*
	    	* 相应的依赖请参照
	    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
	    	*/
	    	HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
	    	System.out.println(response.toString());
	    	//获取response的body
	    	System.out.println(EntityUtils.toString(response.getEntity()));
	    	
	    	JSONObject ret = JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
	    	JSONObject ret2=(JSONObject) ret.get("showapi_res_body");
	    	
	    	return ret2.get("ret_code")+"";
	    } catch (Exception e) {
	    	e.printStackTrace();
	    }
	    return null;
    }
    
    public static void main(String[] args) {
    	JSONObject ret = JSONObject.parseObject("{\"showapi_res_code\":0,\"showapi_res_error\":\"\",\"showapi_res_body\":{\"ret_code\":\"1\",\"successCounts\":\"1\",\"remark\":\"提交成功!\",\"taskID\":\"1708181446019650001\"}}");
    	JSONObject ret2=(JSONObject) ret.get("showapi_res_body");
		System.out.println(ret2.get("ret_code")+"");
	}
}
